package com.yn.xgame.logic;

import java.util.HashMap;
import java.util.Map;

/**
 * GamePlayerManager
 * Created by wangboo on 17/7/13.
 */
public class GamePlayerManager {
	
	// user - player
    private Map<Integer, GamePlayer> map = new HashMap<>(256);
    // session - player
    private Map<Long, GamePlayer> sessionMap = new HashMap<>(256);

    private Map<String, GamePlayer> nameMap = new HashMap<>(256);
    
    private Map<String, GamePlayer> tokenMap = new HashMap<>(256);
    
    

    public GamePlayerManager() {
        GamePlayer player = new GamePlayer(1);
        player.setSessionId(1);
        player.setUserName("a");
        player.setLogicTopic("logic1");
        player.setUserId(1);
        player.setUserWalletGold("1000000");
        player.setUserLevel(1);
        player.setUserVipLevel(1);
        player.setUserIcon(1);
        player.setUserExp(0);
        player.setUserNickName("aaa");
        player.setUserCode(1);
        player.setUserBankGold("100");
        player.setPwd("123456");
        player.setUserHorn(1);
        player.setToken("aaaaaaaaaa");
        player.setGateTopic("gate1");
        add(player);

        player = new GamePlayer(2);
        player.setSessionId(2);
        player.setUserName("b");
        player.setLogicTopic("logic1");
        player.setUserId(2);
        player.setUserWalletGold("1000000");
        player.setUserLevel(1);
        player.setUserVipLevel(1);
        player.setUserIcon(1);
        player.setUserExp(0);
        player.setUserNickName("bbb");
        player.setUserCode(1);
        player.setUserBankGold("100");
        player.setPwd("123456");
        player.setUserHorn(1);
        player.setToken("bbbbbbbbbbb");
        player.setGateTopic("gate1");
        add(player);
    }

    public void add(GamePlayer player) {
        map.put(player.getUserId(), player);
        sessionMap.put(player.getSessionId(), player);
        nameMap.put(player.getUserName(), player);
        tokenMap.put(player.getToken(), player);
    }

    public void remove(int userId) {
        map.remove(userId);
    }
    public void removeBySid(long sid) {
        sessionMap.remove(sid);
    }

    public GamePlayer getPlayer(int userId) {
        return map.get(userId);
    }

    public GamePlayer getPlayerByName(String userName) {
        return nameMap.get(userName);
    }
    
    public GamePlayer getPlayerBySessionId(long sId) {
        return sessionMap.get(sId);
    }
    
    public GamePlayer getPlayerByToken(String token) {
    	return tokenMap.get(token);
    }

    public int size() {
        return map.size();
    }

}
